<?php

namespace Application\Form;

use Zend\Form\Form;
use Application\Model\Contact;
use Zend\Captcha;
use Zend\Form\Element;
use Zend\Log\Logger;


class CraForm extends Form
{
	public function __construct()
	{
		
		parent::__construct("Cra_Form");
		 
		$this->setAttribute('method', 'post');
		 
		$this->add(array(
				'name' => 'id_cra',
				'attributes' => array(
						'type'  => 'hidden',
				),
		));
		 
		$this->add(array(
				'type' => 'Zend\Form\Element\Select',
				'name' => 'mois',
				'options' => array(
						'label' => 'Mois',
						'value_options' => array(
								'1' => 'Choisir le mois',
								'2' => 'Janvier',
								'3' => 'Février',
								'4' => 'Mars',
								'5' => 'Avril',
								'6' => 'Mai',
								'7' => 'Juin',
								'8' => 'Juillet',
								'9' => 'Aout',
								'10' => 'Septembre',
								'11' => 'Octobre',
								'12' => 'Novembre',
								'13' => 'Decembre'
						),
				),
				'attributes' => array(
						'value' => '1' 
				)
		));
		
		$this->add(array(
				'name' => 'nbre_jours',
				'attributes' => array(
						'type'  => 'text',
				),
				'options' => array(
						'label' => _('Nbre de jours travaillés'),
				),
		));
		
		$this->add(array(
				'name' => 'date_jour',
				'id'  => 'datepicker',
				'attributes' => array(
						'type'  => 'Zend\Form\Element\DateTimeLocal',
		
						'value' =>  date("Y-m-d"),
		
				),
				'options' => array(
						'label' => _('Date du jour'),
				),
		));

		$this->add(array(
				'name' => 'description',
				'attributes'=>array(
						'type'=>'textarea'
				),
				'options' => array(
						'label' => _('Description'),
				),
		));
		
	
		$this->add(array(
				'name' => 'submit',
				'attributes' => array(
						'type'  => 'submit',
						'width' => '30px',
						'value' => 'Valider',
						'id' => 'submitbutton',
				),
		));
	}
	 
	
	//IF YOU WILL WORK WITH DATABASE
	//AND NEED bind() FORM FOR EDIT DATA, YOU NEED OVERRIDE
	//populateValues() FUNC LIKE THIS
	public function populateValues($data)
	{
		foreach($data as $key=>$row)
		{
			if (is_array(@json_decode($row))){
				$data[$key] =   new \ArrayObject(\Zend\Json\Json::decode($row), \ArrayObject::ARRAY_AS_PROPS);
			}
		}
		 
		parent::populateValues($data);
	}
}

?>